"use strict";
const common_vendor = require("../../../../common/vendor.js");
const _sfc_main = {
  __name: "SystemMessage",
  setup(__props) {
    common_vendor.dayjs.extend(common_vendor.relativeTime);
    common_vendor.dayjs.extend(common_vendor.localeData);
    common_vendor.dayjs.locale("zh-cn");
    const messages = common_vendor.ref([]);
    const ws = new WebSocket("ws://localhost:8081");
    ws.onmessage = (event) => {
      const data = JSON.parse(event.data);
      data.time = common_vendor.dayjs(data.time);
      messages.value.push(data);
    };
    common_vendor.onMounted(() => {
      ws.onopen = () => {
        console.log("WebSocket连接已打开");
      };
      ws.onerror = (error) => {
        console.error("WebSocket连接错误", error);
      };
      ws.onclose = () => {
        console.log("WebSocket连接已关闭");
      };
    });
    const formatMessageTime = (time) => {
      const now = common_vendor.dayjs();
      if (time.isSame(now, "day")) {
        return time.format("HH:mm");
      } else if (time.isSame(now.subtract(1, "day"), "day")) {
        return `昨天 ${time.format("HH:mm")}`;
      } else if (time.isAfter(now.subtract(1, "week"))) {
        return `${time.format("dddd")} ${time.format("HH:mm")}`;
      } else {
        return time.format("MM月DD日 HH:mm");
      }
    };
    return (_ctx, _cache) => {
      return {
        a: common_vendor.f(messages.value, (message, k0, i0) => {
          return common_vendor.e({
            a: common_vendor.t(formatMessageTime(message.time)),
            b: common_vendor.t(message.title),
            c: message.type === "medication"
          }, message.type === "medication" ? {
            d: common_vendor.t(message.info),
            e: common_vendor.t(message.serviceTime),
            f: common_vendor.t(message.note)
          } : message.type === "doctor" ? {
            h: common_vendor.t(message.doctor),
            i: common_vendor.t(message.content)
          } : {}, {
            g: message.type === "doctor",
            j: message.id
          });
        })
      };
    };
  }
};
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-668df80f"]]);
wx.createPage(MiniProgramPage);
